Fixes #789: Wait for DB type initialization before querying#1081
Open
danielfrankcom wants to merge 1 commit intoporsager:masterfrom
Open
Fixes #789: Wait for DB type initialization before querying#1081danielfrankcom wants to merge 1 commit intoporsager:masterfrom
danielfrankcom wants to merge 1 commit intoporsager:masterfrom
Conversation
4a0fe34 to
3a43815
Compare
Owner
|
Nice work - I'm out of time tonight, but hope I can look closer soon. |
jaisal1024
reviewed
Dec 3, 2025
| needsTypes = false | ||
|
|
||
| // Store the promise so concurrent requests can wait for type initialization to complete | ||
| typesPromise = fetchArrayTypes().finally(() => { |
There was a problem hiding this comment.
if this promise rejects, it throws a global promise rejection. Is there anyway to pipe through an onError handler for new connections
Again thank you for this fix, its very much needed by our team
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #789 by storing the array types request for potential promise chaining, if a query occurs before the types have finished being retrieved.
As described by #789, queries which use
sql.array()can fail if they use a fresh connection. This can be seen in the "Array of Date" test within this repository, if the test is run by itself (usingot()).After some investigation/debugging, it looks like there is a race condition between the completion of the
fetchArrayTypesmethod, and the scheduling of the subsequent query. In my debugger, I was able to see the call toexecuteproceed far enough that thetypeArrayMapwas not updated before the query types were processed. Shortly after this, thefetchArrayTypesmethod completed and updated thetypeArrayMap, but it was already too late.The reason the "Array of Date" test doesn't fail as part of the test suite is because the types are initialized by the other tests that run before it. This is a timing sensitive issue, and if a test that does not use array types runs first then the types get initialized without any problems.
Please note I've run
npm buildand included the generated code as part of this PR. I'm not sure if that is the recommended approach to PRs for this project, or if the generated code will be built as part of the release process. I'm happy to amend the change set if necessary. I couldn't find aCONTRIBUTING.mdfile or contributor instructions anywhere but it's possible I missed them.